//
//  Person.m
//  OC05_Homework
//
//  Created by dllo on 16/7/8.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person

- (instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age
{
    self = [super init];
    if (self) {
        _name = name;
        _sex = sex;
        _age = age;
    }
    return self;
}
+ (instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age
{
    return [[[Person alloc] initWithName:name sex:sex age:age] autorelease];
}
- (NSString *)description
{
    return [NSString stringWithFormat:@"name = %@ sex = %@ age = %ld", _name, _sex, _age];
}
- (NSComparisonResult)sortByAge:(Person *)person
{
    if (self.age > person.age) {
        return NSOrderedDescending;
    } else if (self.age == person.age) {
        return NSOrderedSame;
    } else {
        return NSOrderedAscending;
    }
}
- (NSComparisonResult)sortByName:(Person *)person
{
    return [self.name compare:person.name];
}
- (NSComparisonResult)sortBySex:(Person *)person
{
    return [self.sex compare:person.sex];
}

@end
